package com.ecommerce.model;

import java.util.Date;

public class InventoryHistory {
    private int id;
    private int productId;
    private String productName;
    private String changeType;
    private int changeQuantity;
    private int previousStock;
    private int newStock;
    private String reason;
    private int createdBy;
    private String createdByName;
    private Date createdAt;

    public InventoryHistory() {}

    public InventoryHistory(int productId, String changeType, int changeQuantity,
                            int previousStock, int newStock, String reason, int createdBy) {
        this.productId = productId;
        this.changeType = changeType;
        this.changeQuantity = changeQuantity;
        this.previousStock = previousStock;
        this.newStock = newStock;
        this.reason = reason;
        this.createdBy = createdBy;
    }

    // Getters and Setters
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }

    public int getProductId() { return productId; }
    public void setProductId(int productId) { this.productId = productId; }

    public String getProductName() { return productName; }
    public void setProductName(String productName) { this.productName = productName; }

    public String getChangeType() { return changeType; }
    public void setChangeType(String changeType) { this.changeType = changeType; }

    public int getChangeQuantity() { return changeQuantity; }
    public void setChangeQuantity(int changeQuantity) { this.changeQuantity = changeQuantity; }

    public int getPreviousStock() { return previousStock; }
    public void setPreviousStock(int previousStock) { this.previousStock = previousStock; }

    public int getNewStock() { return newStock; }
    public void setNewStock(int newStock) { this.newStock = newStock; }

    public String getReason() { return reason; }
    public void setReason(String reason) { this.reason = reason; }

    public int getCreatedBy() { return createdBy; }
    public void setCreatedBy(int createdBy) { this.createdBy = createdBy; }

    public String getCreatedByName() { return createdByName; }
    public void setCreatedByName(String createdByName) { this.createdByName = createdByName; }

    public Date getCreatedAt() { return createdAt; }
    public void setCreatedAt(Date createdAt) { this.createdAt = createdAt; }

    @Override
    public String toString() {
        String typeText = getChangeTypeText();
        String direction = changeQuantity >= 0 ? "+" : "";
        return String.format("商品: %s | 类型: %s | 变更: %s%d | 库存: %d → %d | 时间: %s",
                productName, typeText, direction, changeQuantity,
                previousStock, newStock, createdAt);
    }

    public String getChangeTypeText() {
        switch (changeType) {
            case "purchase": return "采购入库";
            case "sale": return "销售出库";
            case "adjustment": return "库存调整";
            case "return": return "退货入库";
            default: return changeType;
        }
    }
}
